<template>
  <div class="run-modal-style" style="height: 460px;">
     <SelfAdaption slot="adaption-bar">
      <Form :model="AddressGroupsearchForm" ref="formSearch" slot="adaption-bar" class="ivu-form-no-margin-bottom" inline>
        <Form-item label="收件人组名：">
            <Input
                type="text"
                placeholder="请输入收件人组名"
                v-model="AddressGroupsearchForm.groupName"
            ></Input>
        </Form-item>
         <Form-item label="单位名称：">
            <Select
            filterable
            style="width: 100%;"
            clearable
            placeholder="请选择单位名称"
            v-model="AddressGroupsearchForm.trgNode"
            >
              <Option v-for="item in bussinessUnitList" :value="item.value" :key="item.value">{{item.value}}</Option>
            </Select>
        </Form-item>
        <Form-item label="领域：">
            <!-- <Input
                type="text"
                placeholder="请输入领域"
                v-model="AddressGroupsearchForm.reportName"
            ></Input> -->
            <Select filterable v-model="AddressGroupsearchForm.reportName">
              <Option v-for="item in areaCodeList" :value="item.value" :key="item.key">{{
                item.value
              }}</Option>
            </Select>
        </Form-item>
        <!--  查询 -->
        <Form-item prop="button" class="search-solt-btn">
          <RPButton optType="search" ref='search' @click="searchAddressGroupValue" />
        </Form-item>
      </Form>
    </SelfAdaption>
    <InnerPageTable ref="AddressGroupTable" :config="pageTableConfig">
    </InnerPageTable>
  </div>
</template>

<script>
import addressGroupApi from '@/api/addressGroup.js'
import coverApi from '@/api/cover.js'
import todoApi from '@/api/todoCender.js'
import {
  ADDRESS_GROUP_STATE_LIST,
  ADDRESS_GROUP_STATE_EFFECTIVE
} from './const.js'
let columns = [
    {
      type: "selection",
      width: 45,
      align: "center"
    },
    // {
      //   title: '报表类型',
    //   key: 'reportType',
    //   width: 90
    // },
    // {
      //   title: '报表名称',
    //   key: 'reportName'
    // },
    {
      title: '领域',
      key: 'reportName'
    },
    {
      title: '单位名称',
      key: 'trgNode'
      // width: 300,

    },
    {
      title: '收件人组名',
      key: 'groupName'
      // width: 200,
    },
  ]
export default {
    data(){
      return{
          actions: [
            {
                text: "取消",
                handle: () => {
                    this.$emit("Close");
                }
            },
            {
                text: "确认",
                theme: "primary",
                icon: "save",
                //handle: this.save,
                  handle: () => {
                     this.$emit("Close", this.ids);
                  },
                //loading: false
            }

        ],
        pageTableConfig:{
          loadDataFn: this.getAddressGroupList,
          columns:  columns,
          autoFirst: true,
          onSelectionChange: this.onSelectionChange,
          thresholdValue: 200
        },
        AddressGroupsearchForm: {
            groupName: '',
            receiver: '',
            trgNode: '',
            validFlag: ADDRESS_GROUP_STATE_EFFECTIVE,
            reportName: '',
          },
        bussinessUnitList:[],
        menuNo: 'addressGroup',
        addressGroupStatusList: ADDRESS_GROUP_STATE_LIST,
        ids: [],
        allreportNameList: [],
        reportNameList: [],
        reportTypeList: [],
        areaCodeList: []
      }
    },
    methods:{
      getAreaCodeList() {
        todoApi.getAreaCodeList().then(res => {
          if (res.data.code == 200) {
            this.areaCodeList = res.data.data || []
          }
        })
      },
      getBussinessUnitList() {
        coverApi.getRptTrgnodeTree({parentNodeCode: -1}).then(res => {
          let data = res.data.data
          let result = []
          if (data && data.length > 0) {
            data.forEach(item => {
              result.push({
                text: item.nodeName,
                value: item.nodeName,
                nodeId: item.nodeId
              })
            })
          }
          this.bussinessUnitList = result
        })
      },
      searchAddressGroupValue(){
        this.$refs['AddressGroupTable'].load(this.AddressGroupsearchForm)
      },
      getAddressGroupList: tableObj => {
        let { responseProcess, param } = tableObj
        let { pageNum, pageSize, groupName, receiver, trgNode, validFlag, reportName } = param
        addressGroupApi.getTableList({
          groupName,
          receiver,
          trgNode,
          validFlag: ADDRESS_GROUP_STATE_EFFECTIVE,
          currentPage: pageNum,
          pageSize,
          reportName,
          // sortOrderBy: "DESC",
          // sortPropName: "create_time"
        }).then(res => {
        let { current, size, records, pages, total  } = res.data.data
          responseProcess({
            pageNum: current,
            size,
            pages,
            records: records || [],
            total,
          });
        })
      },
      init() {
        this.getBussinessUnitList()
        this.getAreaCodeList()
      },
      onSelectionChange(selection) {
        this.ids = selection
      },
    },
    mounted() {
      this.init()
    },
    async created(){
      this.$emit("SetTitle", '选择收件人组');
      this.$emit('SetPageWidth', 800)
      this.$emit('setHeight', 700)
      await coverApi.getCodeManage(
          {
            commonPageDTO: { currentPage: 1, pageSize: 10 },
            condition: { tenantCode: 'IT_SHARE_DEVELOP', vsCode: 'REPORT_FORM_TYPE' },
            pageNum: 1,
            pageSize: 10,
            sortDTO: { fieldName: '', orderBy: '' },
            tenantCode: 'IT_SHARE_DEVELOP',
            vsCode: 'REPORT_FORM_TYPE'
          }
        ).then(res => {
          this.reportTypeList = res.data.records
        })
        await coverApi.getCodeManage(
          {
            commonPageDTO: { currentPage: 1, pageSize: 10 },
            condition: { tenantCode: 'IT_SHARE_DEVELOP', vsCode: 'REPORT_FORMS' },
            pageNum: 1,
            pageSize: 10,
            sortDTO: { fieldName: '', orderBy: '' },
            tenantCode: 'IT_SHARE_DEVELOP',
            vsCode: 'REPORT_FORMS'
          }
        ).then(res => {
          this.allreportNameList = res.data.records
        })

      this.init()
      this.$emit("SetPageActions", this.actions);
    },
    watch: {}
}
</script>

<style lang="less" scoped>
/deep/.ivu-select-small .ivu-select-input, .ivu-select-small.ivu-select-multiple .ivu-select-input {
    height: 32px;
    line-height: 32px;
    top: 0;
}
</style>
